<?php

namespace App\Http\Controllers\Weixin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;

use App\Repositories\Eloquent\Biz\SettleRepository as Sel;
use App\Repositories\Eloquent\Mgt\UtilRepository as Util;

use App\Repositories\Eloquent\Lst\PublishRepository as Publish;
use App\Repositories\Eloquent\Lst\DetailRepository as Detail;
use App\Repositories\Eloquent\Lst\StudentRepository as Student;


use App\Repositories\Eloquent\Exm\RecruitRepository as Recruit;
use App\Repositories\Eloquent\Exm\WarehouseRepository as Warehouse;
use App\Repositories\Eloquent\Exm\QuestionRepository as Question;

class SettleController extends Controller
{

    protected $publish, $detail, $student;

    protected $sel, $util, $recruit;

    public function __construct(Publish $publish, Detail $detail, Student $student,
                            Sel $sel, Util $util, Recruit $recruit,Warehouse $warehouse, Question $question)
    {
        parent::__construct();

        $this->publish = $publish;

        $this->detail = $detail;

        $this->student = $student;

        $this->sel = $sel;

        $this->util = $util;

        $this->recruit = $recruit;
        $this->warehouse = $warehouse;
        $this->question = $question;
    }


    public function index(Request $request)
    {
        $user = \Auth::guard()->user();

        $publish = $this->publish->index();

        return view($this->view, compact('user', 'publish'));
    }


    public function confirm(Request $request, $id)
    {
        $user = \Auth::guard()->user();

        $detail = $this->detail->show($id);

        if ($detail instanceof JsonResponse && $detail->getStatusCode() === 404) {
            return abort('404');
        }

        return view($this->view, compact('user', 'detail'));
    }


    public function student(Request $request)
    {
       return $this->student->confirm($request);
    }


    public function sms(Request $request)
    {
        return $this->util->sendSms($request);
    }


    public function postReg(Request $request)
    {
        //dd($request->gendar);
        return $this->sel->register($request);
    }


    public function postLogin(Request $request)
    {
        return $this->sel->login($request);
    }


    public function login()
    {
        return view($this->view);
    }


    public function reg()
    {
        return view($this->view);
    }

    public function logout()
    {
        \Auth::guard()->logout();

        return \Redirect::route('wx.settle.login');
    }

    //有奖征文
    public function recruit()
    {
        return view($this->view);
    }


    public function recruitPost(Request $request)
    {
        return $this->recruit->store($request);
    }

    //有奖答题
    public function quiz()
    {
        $warehouse = $this->warehouse->activity();

        return view($this->view, compact('warehouse'));
    }

    public function quizPost(Request $request)
    {

        return $this->warehouse->setQuiz($request);
    }


    //防疫有奖答题
    public function resist()
    {
        //return redirect('https://mp.weixin.qq.com/s/VzdC-AON7aO712O4U8bhoQ');
        $warehouse = $this->warehouse->activity();

        return view($this->view, compact('warehouse'));
    }

    public function resistPost(Request $request)
    {
        return $this->warehouse->setResist($request);
    }


}